<section>
    <div class="page_title">
        <h2 class="fl">发送站内信</h2>
        <a class="fr top_rt_btn iconfont iconfont-chexiao" href="{:U('admin/Msgtext/index')}">站内信列表</a>
    </div>
    <ul class="ulColumn2">
        <li>
            <span class="item_name" style="width:120px;">站内信标题：</span>
            <input type="text" name="title" placeholder="标题内容在1-20字" class="textbox textbox_295" />
        </li>
        <li>
            <span class="item_name" style="width:120px;">站内信：</span>
            <div style="display: inline-flex;">
                <textarea placeholder="信息内容在1-200字" maxlength="400" class="textarea" name="msg" id="textMsg" style="width:500px;height:100px;"></textarea>
                <span style="display: block;float: right;position: relative;left: 5px;top: 100px;"><i id="msgNums"></i>/200</span>
            </div>
        </li>
        <li>
            <span class="item_name" style="width:120px;">用户组：</span>
            <select class="select" name="mid" id="platform">
                {volist name="module" id="vo"}
                <option value="{$vo['id']}">{$vo['title']}</option>
                {/volist}
            </select>
        </li>
        <li>
            <span class="item_name" style="width:120px;"></span>
            <input type="submit" class="link_btn addmessage" style="margin-left: 300px">
        </li>
    </ul>
</section>
<script type="text/javascript">
    $(function(){
        $("#msgNums").html(0);
        document.getElementById("textMsg").onpropertychange =document.getElementById("textMsg").onkeyup= function(){
            var lenE = this.value.length;
            var tno = document.getElementById("msgNums");
            tno.innerHTML = lenE ;
            if (tno.innerHTML > 200) {
                var tmp = 0 ;
                var cut = this.value.substring(0, 200);
                for (var i=0; i<cut.length; i++){

                    tmp += /[\u4E00-\u9FA5\uF900-\uFA2D]/.test(cut.charAt(i)) ? 2 : 1;

                    if (tmp > 200) break;

                }
                this.value = cut.substring(0, 200);
                msg_warning('至多输入200个字');
            }
        }
    })
</script>
<script>
    $('.addmessage').click(function () {
        var msg = $("textarea[name=msg]").val();
        var title = $("input[name=title]").val();
        if(!title)
        {
            msg_warning('请输入站内信标题');
            return false;
        }
        //选择用户组
        var gorup = $('#platform option:selected').val();
        var data = {msg:msg,gorup:gorup,title:title};
        send_data = {
            url:U('admin/Msgtext/addMessage'),
            type:'POST',
            data:data,
            dataType:'json',
        }
        send_ajax(send_data,function(res){
            if(res.status == 1){
                msg_success('发送成功','操作成功',2000);
                setTimeout(function(){
                    admin.getContentByUrl(res.data.jumpurl);
                },2000);
            }else{
                msg_error(res.message);
            }
        })
    });
    $(function(){
        //调用登陆部分的js
        $(window).keyup(function(e){
            if(e.keyCode == 13){
                $(".addmessage").click();
            }
        })
    });
</script>